# 使用基础 Python 镜像
FROM artifacts.iflytek.com/docker-private/dc/python:3.9

# 更换为阿里云的 apt 镜像源
#RUN sed -i 's|https://deb.debian.org|https://mirrors.aliyun.com|g' /etc/apt/sources.list && \
#    sed -i 's|https://security.debian.org|https://mirrors.aliyun.com|g' /etc/apt/sources.list \

# 安装 tini
#RUN apt-get update && apt-get install -y \
#    gcc \
#    g++ \
#    && apt-get clean \
#    && rm -rf /var/lib/apt/lists/* \
#    && pip install --no-cache-dir tini

RUN mkdir -p /data/server_health
RUN mkdir -p /data/log
RUN touch /data/log/server_health.log

# 设置工作目录
WORKDIR /data/server_health

# 将项目文件拷贝到工作目录
COPY . /data/server_health

# 安装依赖
RUN pip3 install --no-cache-dir -r requirements.txt -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com

# 暴露Django服务端口
EXPOSE 8000

# 使用 Tini 作为初始化进程，并运行多个命令
# ENTRYPOINT ["tini", "--"]

# 运行命令
CMD ["sh", "-c", "\
    (celery -A server_health worker --loglevel=info > /data/log/celeryworker.log 2>&1 &) && \
    (celery -A server_health beat --loglevel=info > /data/log/celerybeat.log 2>&1 &) && \
    uwsgi --ini server_health.ini && \
    tail -f -n 1000 /data/log/server_health.log"]
